<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
	Object obj = request.getSession().getAttribute("role_resource");
	if (null == obj) {
		response.setStatus(1000);
		return;
	}
%>

<script type="text/javascript">

	var uploadForm = new Ext.Panel({
			id : "uploadForm",
			region : "center",
			title : "文件上传",
			height:	400,
			fileUpload : true,
			frame : true,
			//collapsible: true,
			bodyStyle : "padding: 10px 10px 10px 10px;",
			items : [ {
				xtype: "fieldset",
				title: "个性化数据上传",
				layout: "column",
				autoHeight: true,
				items:[{
					columnWidth: .8,
					id:"gxhData",
					xtype: "form",
					fileUpload: true,
					layout: "form",
					items:[{
							id: "gxhupload",
							fieldLabel : "个性化数据",
							xtype : "fileuploadfield",
							emptyText : "请选择文件",
							name : "file",
							anchor : "95%",
							validator : function(input){
								var str = input.substring(input.lastIndexOf('.')+1);
								if(''==input) return false;
								if('txt'==str){
									return true;
								}else{
									return "只限上传txt文件！";
								}
							}
						}, {
							xtype : "textfield",
							name : "type",
							hidden : true,
							value : "gxhData"
					}]
				},{
				columnWidth : .1,
						layout : "form",
						items :[{
							xtype : "button",
							text : "上传文件",
							handler : function() {
								var v = Ext.getCmp("gxhupload").getValue();
								if(''==v){
									Ext.Msg.show({
										title: "Selected File",
							            msg: v&&v!='' ? v:'未选择文件！',
							            minWidth: 200,
							            modal: true,
							            icon: Ext.Msg.INFO,
							            buttons: Ext.Msg.OK
									});
									return;
								}else{
									if (Ext.getCmp("gxhData").getForm().isValid()) {
										Ext.getCmp("gxhData").getForm().submit( {
											url : "upload2.action",
											waitMsg : "正在上传文件...",
											success : function(fp, o) {
												Ext.Msg.show( {
													title : "Success",
													msg : "文件上传成功！",
													minWidth : 200,
													modal : true,
													icon : Ext.Msg.INFO,
													buttons : Ext.Msg.OK
												});
											}
										});
									}
								}	
						}
					}]
				} ]
			}]
		});
	
	var upload_pel = new Ext.Panel( {
		id : "myPanel",
		layout : "border",
		border:false,
		buttonAlign: "center",
		buttons:[{
			id: "parseButton",
				text : "导入上传的文件",
				width : 250,
				handler : function() {
					Ext.Ajax.request({
						url : 'upload2!parseFile.action',
						waitMsg : "正在解析文件...",
						success : function(fp, o){
							if(null==fp || fp.responseText=='' ){
								Ext.Msg.show( {
									title : 'Success',
									msg : "文件解析成功！",
									minWidth : 200,
									modal : true,
									icon : Ext.Msg.INFO,
									buttons : Ext.Msg.OK
								});
							//	Ext.getCmp("parseButton").setDisabled(true);
							}else{
								Ext.Msg.show( {
									title : 'Success',
									msg : fp.responseText,
									minWidth : 200,
									modal : true,
									icon : Ext.Msg.INFO,
									buttons : Ext.Msg.OK
								});
							}
						}
					});
				}
		}],
		items : [ uploadForm ]
	});
	
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(upload_pel);
	CenterPanel.doLayout();	
	
</script>

